package com.minivision.sdktestdemo.theme.ui;

import android.content.Context;
import android.content.res.Resources;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;

import com.minivision.sdktestdemo.theme.utils.CustomThemeInterface;
import com.minivision.sdktestdemo.theme.utils.ThemeUtils;
import com.minivision.sdktestdemo.theme.utils.ViewAttributeUtils;

/**
 * Created by Administrator on 2016/6/21.
 */
public class CustomThemeImageView extends ImageView implements CustomThemeInterface {
    private int attrTintColor = -1;

    public CustomThemeImageView(Context context) {
        super(context);
    }

    public CustomThemeImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
        attrTintColor = ViewAttributeUtils.getTintColorAttribute(attrs);
    }

    public CustomThemeImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        attrTintColor = ViewAttributeUtils.getTintColorAttribute(attrs);
    }

    @Override
    public View getView() {
        return this;
    }

    @Override
    public void setTheme(Resources.Theme themeId) {
        if (attrTintColor != -1) {
            if (ViewAttributeUtils.isNeedChangeColor(this)) {
                setColorFilter(ThemeUtils.getThemeColor());
            } else {
                ViewAttributeUtils.applyTintColor(this, themeId, attrTintColor);
            }
        }
    }
}
